//package mn.idax.exchange.otc.task;
//
//import com.dangdang.ddframe.job.api.ShardingContext;
//import com.dangdang.ddframe.job.api.simple.SimpleJob;
//import com.dangdang.elasticjob.lite.annotation.ElasticSimpleJob;
//import mn.idax.exchange.otc.domain.OrderChat;
//import mn.idax.exchange.otc.enums.MessageTypeEnum;
//import mn.idax.exchange.otc.util.LogUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.domain.Sort;
//import org.springframework.data.mongodb.core.MongoTemplate;
//import org.springframework.data.mongodb.core.query.Criteria;
//import org.springframework.data.mongodb.core.query.Query;
//import org.springframework.data.mongodb.core.query.Update;
//import org.springframework.stereotype.Component;
//
//import java.util.ArrayList;
//import java.util.List;
//import java.util.concurrent.ConcurrentLinkedQueue;
//
///**
// * @Author: jack_huang
// * @Date: 2019/8/16 16:24
// */
//@ElasticSimpleJob(cron = "0 0/2 * * * ?")
//@Component
//public class FixMongoPicUrlJob implements SimpleJob {
//
//    @Autowired
//    private MongoTemplate mongoTemplate;
//
//    @Override
//    public void execute(ShardingContext shardingContext) {
//
//        long start = System.currentTimeMillis();
//
//        //http://otcpublic.oss-cn-hangzhou.aliyuncs.com/20181102/b67f60b5d6794d2eb87c789d0bb05ab9.jpg
//
//        //聊天图片查询条件
//        Query chatPicQuery = new Query();
//        chatPicQuery.addCriteria(new Criteria().andOperator(
//                Criteria.where("msgType").is(MessageTypeEnum.image).and("source").regex("^http://otcpublic.oss")
//        ));
//        chatPicQuery.limit(2000);
//        List<OrderChat> chatPicQueryList = new ArrayList<>(2000);
//        chatPicQueryList = mongoTemplate.find(chatPicQuery, OrderChat.class);
//
//        long querychatPic = System.currentTimeMillis();
//        LogUtils.info(this.getClass(),"fixMongoPicUrlJobQueryChat  cost: " + (querychatPic - start) + " chatPicQueryList size: " + chatPicQueryList.size());
//
//        if (!chatPicQueryList.isEmpty()){
//            for (OrderChat orderChat : chatPicQueryList) {
//                String source = orderChat.getSource();
//                if (source.length() > 45 && source.startsWith("http")){
//                    Update update = new Update();
//                    update.set("source", source.substring(45));
//                    Query updateQuery = new Query(Criteria.where("uuid").is(orderChat.getUuid()));
//
//                   mongoTemplate.updateFirst(updateQuery, update, OrderChat.class);
//                }
//            }
//        }
//
//        //userlogo query
//        long queryUserLogoStart = System.currentTimeMillis();
//        Criteria c1 = Criteria.where("userLogo").regex("^http://otcpublic.oss");
//        Sort sort = new Sort(Sort.Direction.DESC, "sendTime");
//        Query userLogoQuery = new Query(c1).with(sort);
//        userLogoQuery.limit(2000);
//        List<OrderChat> userLogoQueryList = mongoTemplate.find(userLogoQuery, OrderChat.class);
//        long queryUserLogo = System.currentTimeMillis();
//        LogUtils.info(this.getClass(),"fixMongoPicUrlJobQueryChat  cost: " + (queryUserLogo - queryUserLogoStart) + " userLogoQueryList size: " + userLogoQueryList.size());
//
//        if (!userLogoQueryList.isEmpty()){
//            for (OrderChat orderChat : userLogoQueryList) {
//                String userLogo = orderChat.getUserLogo();
//                if (userLogo.length() > 45 && userLogo.startsWith("http")){
//                    Update update = new Update();
//                    update.set("userLogo", userLogo.substring(45));
//                    Query updateQuery = new Query(Criteria.where("uuid").is(orderChat.getUuid()));
//
//                    mongoTemplate.updateFirst(updateQuery, update, OrderChat.class);
//                }
//
//            }
//        }
//
//        long end = System.currentTimeMillis();
//        long cost = end - start;
//        LogUtils.info(this.getClass(),"fixMongoPicUrlJob  cost: " + cost + " inflince: " + (chatPicQueryList.size() + userLogoQueryList.size()));
//
////        dealUrl(CHAT_IMG_SOURCE_QUEUE,USER_LOGO_QUEUE);
//    }
//
//    public void  dealUrl(ConcurrentLinkedQueue<OrderChat>  chatQueue,ConcurrentLinkedQueue<OrderChat> userLogQueue){
//
//
//    }
//}
